package com.chia.multienty.core.service.impl;

import com.chia.multienty.core.pojo.WechatMppScene;
import com.chia.multienty.core.mapper.WechatMppSceneMapper;
import com.chia.multienty.core.service.WechatMppSceneService;
import com.chia.multienty.core.mybatis.service.impl.KutaBaseServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.chia.multienty.core.domain.dto.WechatMppSceneDTO;
import com.chia.multienty.core.parameter.wechat.WechatMppSceneDetailGetParameter;
import com.chia.multienty.core.parameter.wechat.WechatMppScenePageGetParameter;
import com.chia.multienty.core.parameter.wechat.WechatMppSceneDeleteParameter;
import com.chia.multienty.core.parameter.wechat.WechatMppSceneSaveParameter;
import com.chia.multienty.core.parameter.wechat.WechatMppSceneUpdateParameter;
import com.github.yulichang.toolkit.MPJWrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import com.chia.multienty.core.domain.constants.MultientyConstants;
import com.chia.multienty.core.mybatis.MTLambdaWrapper;
import com.chia.multienty.core.util.ListUtil;
import com.chia.multienty.core.domain.enums.StatusEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chia.multienty.core.tools.MultientyContext;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.chia.multienty.core.tools.IdWorkerProvider;
/**
 * <p>
 * 微信小程序场景 服务实现类
 * </p>
 *
 * @author Multienty Auto Generator
 * @since 2024-06-26
 */
@Service
@RequiredArgsConstructor
@DS(MultientyConstants.DS_SHARDING)
public class WechatMppSceneServiceImpl extends KutaBaseServiceImpl<WechatMppSceneMapper, WechatMppScene> implements WechatMppSceneService {


    @Override
    public WechatMppSceneDTO getDetail(WechatMppSceneDetailGetParameter parameter) {
        return selectJoinOne(WechatMppSceneDTO.class,
                        MPJWrappers.<WechatMppScene>lambdaJoin()
                        .eq(WechatMppScene::getTenantId, parameter.getTenantId())
                        .eq(WechatMppScene::getSceneId, parameter.getSceneId()));
    }

    @Override
    public void update(WechatMppSceneUpdateParameter parameter) {
        WechatMppScene wechatMppScene = new WechatMppScene();
        BeanUtils.copyProperties(parameter, wechatMppScene);
        updateByIdAndSharding(wechatMppScene);
    }

    @Override
    public void delete(WechatMppSceneDeleteParameter parameter) {
        removeTE(new LambdaQueryWrapper<WechatMppScene>()
                .eq(WechatMppScene::getTenantId, parameter.getTenantId())
                .eq(WechatMppScene::getSceneId, parameter.getSceneId()));
    }

    @Override
    public IPage<WechatMppSceneDTO> getPage(WechatMppScenePageGetParameter parameter) {
        return selectJoinListPage(parameter.getPageObj(), WechatMppSceneDTO.class,
                new MTLambdaWrapper<WechatMppScene>()
                        .solveGenericParameters(parameter)
                        .eq(WechatMppScene::getTenantId, parameter.getTenantId())
                        .in(!ListUtil.isEmpty(parameter.getSceneIds()),
                                WechatMppScene::getSceneId,
                                parameter.getSceneIds())
        );
    }

    @Override
    public void save(WechatMppSceneSaveParameter parameter) {
        WechatMppScene wechatMppScene = new WechatMppScene();
        BeanUtils.copyProperties(parameter, wechatMppScene);
        wechatMppScene.setSceneId(IdWorkerProvider.next());

        wechatMppScene.setTenantId(MultientyContext.getTenant().getTenantId());
        saveTE(wechatMppScene);
        parameter.setSceneId(wechatMppScene.getSceneId());
    }


}
